package bi

import android.content.Context
import android.provider.Settings
import android.text.TextUtils
import java.lang.reflect.Method

class GK {

    companion object{
        /**
         * 获取华为系统版本名称
         * @return String  返回值：harmony
         */
        fun osBandName(): String? {
            try {
                val clz = Class.forName("com.huawei.system.BuildEx")
                return clz.getMethod("getOsBrand").invoke(clz) as String
            } catch (e: Throwable) {
                e.printStackTrace()
            }
            return ""
        }

        /**
         * 获取华为系统版本号
         * @return 版本号
         */
        fun harmonyOsv(): String? {
            return getProp("hw_sc.build.platform.version", "")
        }

        private fun getProp(property: String, defaultValue: String): String? {
            try {
                val spClz = Class.forName("android.os.SystemProperties")
                val method: Method = spClz.getDeclaredMethod("get", String::class.java)
                val value = method.invoke(spClz, property) as String
                return if (TextUtils.isEmpty(value)) {
                    defaultValue
                } else value
            } catch (e: Throwable) {
                e.printStackTrace()
            }
            return defaultValue
        }




        fun isHarmonyOs(): Boolean {
            return try {
                val buildExClass = Class.forName("com.huawei.system.BuildEx")
                val osBrand = buildExClass.getMethod("getOsBrand").invoke(buildExClass)
                "Harmony".equals(osBrand.toString(), ignoreCase = true)
            } catch (x: Throwable) {
                false
            }
        }

        /**
         * 获取鸿蒙纯净模式状态
         * 0：开启，1：关闭
         *
         * @param context
         * @return
         */
        fun readPureModeState(context: Context?): Int {
            var result = 1
            if (!isHarmonyOs()) {
                return result
            }
            try {
                if (context != null) {
                    result =
                        Settings.Secure.getInt(context.contentResolver, "pure_mode_state", 0)
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
            return result
        }
    }




}